package com.xbdun.web.bmp.service;

import java.util.List;

import com.alibaba.dubbo.common.utils.CollectionUtils;
import com.alibaba.dubbo.config.annotation.Reference;
import com.xbdun.common.api.Client;
import com.xbdun.comweb.bmp.session.IUserAuth;
import com.xbdun.facade.bmp.constant.DubboBmpConst;
import com.xbdun.facade.bmp.response.system.PlatformMenuResponse;
import com.xbdun.facade.bmp.service.system.OpenAuthFacade;

/**
* @ClassName: UserAuthService
* @Description: 本地缓存个人权限
* @author zhanggt 360730440@qq.com
* @date 2017年5月11日 下午7:48:10
*/
public class UserAuthService implements IUserAuth{
	@Reference(registry=DubboBmpConst.REGISTRYS)
	OpenAuthFacade openAuthFacade;
	
	/**写入缓存*/
	public String putInUserAuth(Client client){
		return ","+openAuthFacade.getUserAuthEvent(client)+",";
	}
	/**获取缓存*/
	public String getUserAuth(Client client){
		return ","+openAuthFacade.getUserAuthEvent(client)+",";
	}
	
	/**删除缓存*/
	public void removeUserAuth(Client client){}
	
	public String putInAllPlatform(String menuKey, String value) {
		return value;
	}
	
	public String getSysPlatAuth(String menuKey) {
		return openAuthFacade.getSysPlatAuth(menuKey);
	}
	
	public void initPlatform(int platCode){
		removePlatAuth();
		List<PlatformMenuResponse> platformMenu = openAuthFacade.getPlatformMenu(platCode);
		if(CollectionUtils.isNotEmpty(platformMenu)){
			for(PlatformMenuResponse dto:platformMenu){
				putInAllPlatform(dto.getMenuCode(),dto.getMenuNameHit());
			}
			platformMenu.clear();
		}
		if(null!=platformMenu){
			platformMenu = null;
		}
	}
	
	public String getCurrentOrgAuth(long orgCode, int platCode) {
		return ","+openAuthFacade.getCurrentOrgAuth(orgCode,platCode)+",";
	}
	
	public void removePlatAuth() {}
	public void removeCurrentOrgAuth(long orgCode, int platCode) {}
}
